<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]='formGroup' [lvLabelColon]="false" class="formGroup">
  <lv-alert lvType="info" lvClosable="false"
    *ngIf="formGroup.value.backupProxyFile === dataMap.Backup_Proxy_File.DownLoad.value">
    {{'protection_proxy_download_tip_label' | i18n}}
  </lv-alert>
  <lv-form-item>
    <lv-form-label lvRequired>{{'protection_incremental_mode_label' | i18n}}</lv-form-label>
    <lv-form-control>
      <lv-select [lvOptions]='backupProxyTypeOptions' lvValueKey='value' formControlName='backupProxyFile' [lvDisabled]="isMultiStandbyNode">
      </lv-select>
    </lv-form-control>
  </lv-form-item>
  <ng-container *ngIf="formGroup.value.backupProxyFile === dataMap.Backup_Proxy_File.DownLoad.value">
    <lv-form-item>
      <lv-form-label lvRequired>{{'protection_proxy_type_label' | i18n}}</lv-form-label>
      <lv-form-control>
        <lv-select formControlName="proxyType" lvValueKey="value" [lvOptions]="downloadProxyOptions">
        </lv-select>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item>
      <lv-form-label lvRequired>{{'protection_os_type_label' | i18n}}</lv-form-label>
      <lv-form-control>
        <lv-select [lvOptions]='osTypeOptions' lvValueKey='value' formControlName='osType'>
        </lv-select>
      </lv-form-control>
    </lv-form-item> 
    <lv-form-item *ngIf="formGroup.value.osType === dataMap.OS_Type.Linux.value">
      <lv-form-label lvRequired>
        {{'protection_download_type_label' | i18n}}
      </lv-form-label>
      <lv-form-control>
        <lv-select [lvOptions]='packageTypeOps' lvValueKey='value' formControlName='packageType'>
        </lv-select>
      </lv-form-control>
    </lv-form-item>
    <ng-container *ngIf="formGroup.value.proxyType === dataMap.Proxy_Type_Options.remoteAgent.value">
      <lv-form-item>
        <lv-form-label lvRequired>
          {{'protection_host_applications_label' | i18n}}
        </lv-form-label>
        <lv-form-control>
          <lv-tree-select [lvTreeData]="treeData" lvTreeSelectionMode="multiple" lvTreeShowCheckbox lvTreeShowLine
          lvShowFilter lvFilterKey="label" lvFilterMode="contains" lvSelectedValueMode="parent" formControlName="applications"></lv-tree-select>
        </lv-form-control>
      </lv-form-item>
    </ng-container>
    <!-- 共享 -->
    <ng-container
    *ngIf="!isHcsUser && (formGroup.value.proxyType === dataMap.Proxy_Type_Options.remoteAgent.value) && formGroup.value.osType === dataMap.OS_Type.Linux.value">
        <lv-form-item>
            <lv-form-label>{{'protection_multi-tenant_sharing_label' | i18n}}
                <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_multi-tenant_sharing_tips_label' | i18n}}" lvTooltipTheme="light"
                    lvTooltipPosition="right" class="configform-constraint" lvColorState="true"></i>
            </lv-form-label>
            <lv-form-control>
                <lv-radio-group formControlName="isShared" [lvGroupName]="'shareGroup'" [lvDisabled]="shareDisabled">
                    <lv-group [lvGutter]="'24px'">
                        <lv-radio lvValue="true">{{'switch_status_on_label' | i18n}}</lv-radio>
                        <lv-radio lvValue="false">{{'switch_status_off_label' | i18n}}</lv-radio>
                    </lv-group>
                </lv-radio-group>
            </lv-form-control>
        </lv-form-item>
    </ng-container>
    <lv-form-item>
      <lv-form-label lvRequired>
        {{'protection_private_key_password_label' | i18n}}
        <i lv-icon="aui-icon-help" [lv-tooltip]="pwdDescTpl" lvTooltipPosition="top" lvTooltipTheme="light"
          class="configform-constraint" lvColorState='true'>
        </i>
      </lv-form-label>
      <lv-form-control [lvErrorTip]="baseUtilService.pwdErrorTip">
        <aui-inupt-with-eye formControlName="privateKeyPwd" [lvPasteAllowed]="false" [lv-tooltip]="pwdComplexTipTpl"
          lvTooltipTrigger="focus" lvTooltipPosition="topLeft" lvTooltipTheme="light"></aui-inupt-with-eye>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item>
      <lv-form-label lvRequired>
        {{'protection_private_key_password_confirm_label' | i18n}}
      </lv-form-label>
      <lv-form-control [lvErrorTip]="baseUtilService.pwdErrorTip">
        <aui-inupt-with-eye formControlName="privateKeyPwdConfirm" [lvPasteAllowed]="false"
          [lv-tooltip]="pwdComplexTipTpl" lvTooltipTrigger="focus" lvTooltipPosition="topLeft" lvTooltipTheme="light">
        </aui-inupt-with-eye>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container *ngIf="formGroup.value.backupProxyFile === dataMap.Backup_Proxy_File.Upload.value">
    <lv-form-item>
      <lv-form-label lvRequired>{{ 'protection_backup_proxy_file_label' | i18n }}</lv-form-label>
      <lv-form-control>
        <lv-upload lvAccept=".zip" lvShowUpload="false" [lvFilters]='filters'></lv-upload>
        <span class="aui-text-help-sm">
          {{'protection_import_backup_proxy_file_label' | i18n}}
        </span>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
</lv-form>

<ng-container *ngIf="formGroup.value.backupProxyFile === dataMap.Backup_Proxy_File.Upload.value">
  <h3 class="title-md">{{'protection_uploaded_agent_file_label' | i18n}}</h3>
  <lv-pro-table #agentTable [config]="agentTableConfig" [data]="agentTableData"></lv-pro-table>
</ng-container>

<ng-template #pwdComplexTipTpl>
  <span [innerHTML]="pwdValidTip"></span>
</ng-template>

<ng-template #pwdDescTpl>
  <span [innerHTML]="'protection_private_key_help_label' | i18n"></span>
</ng-template>
